package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("systemDictionaryItem")
public class SystemDictionaryItemController {

    @Autowired
    private ISystemDictionaryItemService systemDictionaryItemService;

    @RequestMapping("selectByDictionaryId")
    @ResponseBody
    public Object selectByDictionaryId(Long id) {
        return systemDictionaryItemService.selectByDictionaryId(id);
    }

    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public Object saveOrUpdate(SystemDictionaryItem systemDictionary){
        JSONResult result = new JSONResult();
        try {
            systemDictionaryItemService.saveOrUpdate(systemDictionary);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return result.remark("保存失败");
        }
    }

    @RequestMapping("delete")
    @ResponseBody
    public Object delete(Long id){
        JSONResult result = new JSONResult();
        if(id != null){
            try {
                systemDictionaryItemService.delete(id);
                return result;
            } catch (Exception e) {
                e.printStackTrace();
                return result.remark("保存失败");
            }
        }

        return null;
    }

    @RequestMapping("selectByParentId")
    @ResponseBody
    public Object selectByParentId(Long id){
        return systemDictionaryItemService.selectByParentId(id);
    }
    @RequestMapping("getItemBySn")
    @ResponseBody
    public Object getItemBySn(String sn){
        return systemDictionaryItemService.getItemBySn(sn);
    }


}
